<?php
include("inc/class.otr.php");
$otr = new OTR();

if(!$otr->checkLogin()){
	header("Location: index.php");
}

$u = $otr->getUser();

if(isset($_GET['action'])){
	switch($_GET['action']){
		case 'insert':
			$sql = "Insert into `punchclock` (`related_id`, `related_table`, `user_id`, `punch_in`, `punch_out`, `notes`)
					Values (".$_GET['id'].", 'tasks', ".$u['id'].", NOW(), NOW(), '')";
			break;
		case 'update':
			$sql = "Update `punchclock`
					set `punch_out`=NOW()
					Where `related_id`=".$_GET['id']."
					And `user_id`=".$u['id']."
					Order by `id` desc
					Limit 1";
			break;
		case 'note':
			$sql = "Update `punchclock`
					set `notes`='".$_GET['note']."'
					Where `related_id`=".$_GET['id']."
					And `user_id`=".$u['id']."
					Order by `id` desc
					Limit 1";
			break;
	}
	mysql_query($sql) or die(mysql_error()."<br/>failed executing query: ".$sql);
}
echo $otr->getPunchTime($_GET['id'], $u['id']);
?>